<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Role;

class RoleController extends Controller
{
    public function index(Request $request)
    {
    	$where = [];
    	$list = Role::where($where)->paginate(10);
    	return view('admin.role.index',compact('list'));
    }

    public function edit($id)
    {
        $data = Role::find($id);
        return view('admin.role.edit',compact('data'));
    }

    public function store(Request $request)
    {
        $data = $request->only(['name']);
        $flag = Role::create($data);
        if($flag) {
            return back();
        }
    }

     public function update(Request $request, $id)
    {
        $rs['status'] = false;
        $rs['msg'] = '操作失败';
        $data = $request->only('name');
        $flag = Role::where(['id'=>$id])->update($data);
        if($flag) {
            $rs['msg'] = '操作成功';
            return redirect('zadmin/role')->with('rs',$rs);    
        } 
        return back();
        
    }

    public function destroy($id)
    {
        Role::destroy($id);
        return back();
    }
}
